﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.orderDAL;

namespace dhSystemBLL.orderData
{
   public class colorNumListBLL
    {
       private colorNumListTableAdapter _colorNumListAdapter = null;
       private colorNumListTableAdapter colorNumListAdapter
        {
            get
            {
                if (_colorNumListAdapter == null) _colorNumListAdapter = new colorNumListTableAdapter();
                return _colorNumListAdapter;

            }
        }
        /// <summary>
       /// 查询色号对照表
        /// </summary>
        /// <returns></returns>

       public orderDataSet.colorNumListDataTable getcolorNumListAll()
        {
            try
            {
                return colorNumListAdapter.GetDatacolorNumListALL();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
       /// 根据颜色名称查询色号对照表
        /// </summary>
        /// <param name="groupNum"></param>
        /// <returns></returns>
       public orderDataSet.colorNumListDataTable getcolorNumListAll(string colorNuM)
        {
            try
            {
                return colorNumListAdapter.GetDatacolorNumListBycolorNuM(colorNuM);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            /// <summary>
            /// 插入色号对照表
            /// </summary>
            /// <param name="row"></param>
            /// <returns></returns>

        }
       public int colorNumListInsert(colorNumListModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;

            try
            {
                tn = conn.BeginTransaction();
                colorNumListDAL colorNumListUpdate = new colorNumListDAL(tn, conn);
                colorNumListUpdate.colorNumListInsert(row);
                tn.Commit();
                return i;
            }
            catch (SqlException ex)
            {
                tn.Rollback();
                if (ex.Number == 2627)
                {
                    throw new Exception("这个客户编号已经存在");
                }


                throw new Exception(ex.Number.ToString() + ex.Message.ToString());

            }

            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());

            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
       /// 更新色号对照表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
       public int colorNumListUpdate(colorNumListModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                colorNumListDAL colorNumListUpdate = new colorNumListDAL(tn, conn);
                colorNumListUpdate.colorNumListUpdate (row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());

            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
       /// 删除一行色号对照表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
       public int colorNumListDel(string recordid)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                colorNumListDAL colorNumListUpdate = new colorNumListDAL(tn, conn);
                colorNumListUpdate.colorNumListDel(recordid);
                tn.Commit();
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());

            }
            finally
            {
                conn.Close();
            }
        }
    }
}
